#!/bin/bash

set -eux

### --start_docs
## Prepare images for deploying the overcloud
## ==========================================

## Prepare Your Environment
## ------------------------

## * Source in the undercloud credentials.
## ::

source {{ working_dir }}/stackrc

## * Get nodes UUID
## ::

export items="$( openstack baremetal node list | awk '/power/ {print $2}' )"

## * Find disk size from instackenv.json
## ::

export DISK_SIZE="$( jq '.["nodes"][]["disk"] | tonumber' instackenv.json )"

## * Update nodes with disk size hint
## ::

count=0
ARRAY_DISK_SIZE=($(echo $DISK_SIZE))
ROOT_DEVICE_SIZE={{ disk_root_device_size }}
for item in $items; do
    if  [ $ROOT_DEVICE_SIZE -ge ${ARRAY_DISK_SIZE[$count]} ]; then
        declare i ADS
        ADS=${ARRAY_DISK_SIZE[$count]}
        openstack baremetal node set --property root_device='{"size": '$ADS'}' $item
    fi
    count=$((count+1))
done

### --stop_docs
